package com.xcity.game.shop.mystery;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.shop.mystery.template.MysteryShopItemTemplate;

import naga.x.App;

public class PlayerMysteryShopItem {

	@JSONField(name = "0")
	protected int id;
	@JSONField(name = "1")
	protected int count;
	@JSONField(name = "2")
	protected byte state;
	
	protected MysteryShopItemTemplate template; 

	public static final byte STATE_INIT = 0; // 初始化状态(可购买)
	public static final byte STATE_SELL_OUT = 1; // 已卖完(不可购买)
	
	public PlayerMysteryShopItem() {}
	
	public PlayerMysteryShopItem(MysteryShopItemTemplate template) {
		this.id = template.getId();
		this.count = template.getCount();
		this.state = STATE_INIT;
		this.template = template;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public byte getState() {
		return state;
	}

	public void setState(byte state) {
		this.state = state;
	}
	
	@JSONField(serialize = false)
	public String getName() {
		return getTemplate().getRef().getName();
	}
	
	@JSONField(serialize = false)
	public String getIcon() {
		return getTemplate().getRef().getIcon();
	}
	
	@JSONField(serialize = false)
	public String getDesc() {
		return getTemplate().getRef().getDesc();
	}
	
	@JSONField(serialize = false)
	public MysteryShopItemTemplate getTemplate() {
		return template != null ? template : (template = App.getApp().getServiceManager().get(MysteryShopService.class).getTemplate(id, count));
	}

}
